import { createStore, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
import logger from 'redux-logger'
import rootReducer from '../reducers'

import {persistReducer, persistStore} from 'redux-persist'
import storage from 'redux-persist/lib/storage'

// 持久化配置
const persistConfig = {
  key: 'root',
  storage,
}

// 处理根 reducer
const persistedReducer = persistReducer(persistConfig, rootReducer)

// 创建出 store
const store = createStore(persistedReducer, applyMiddleware(thunk, logger))

// 处理 store
const persistor = persistStore(store)

export {store, persistor}
